import { Select, Input, Button, Space, Switch, Pagination, Modal,message } from 'antd';
import * as api from '../../api/Administrator'
const administratorActions = {
  getLogin (obj: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.getLogin(obj).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'getLogin',
        payload,
      });
    };
  },
  setloginName(value: any){
    return {
      type: 'setloginName',
      payload:value,
    };
  },
  setloginPass(value: any){
    return {
      type: 'setloginPass',
      payload:value,
    };
  },
  setjzpass(value: any){
    return {
      type: 'setjzpass',
      payload:value,
    };
  },
  setempty(){//清空密码用户名
    return {
      type: 'setempty',
    };
  },
  getscblist(obj: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.getscblist(obj).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'getscblist',
        payload,
      });
    };
  },
  getcollegelist(){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.getcollegelist({}).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'getcollegelist',
        payload,
      });
    };
  },
  addstudent(obj: any){//添加学员
    console.log(obj);
    
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.addstudent(obj).then((res)=>{
        message.success('添加成功');
        return res.data;
        
      }).catch(()=>{
        // message.success('添加失败');
        message.error('添加失败');
        
      })
      dispatch({
        type: 'addstudent',
        payload,
      });
    };
  },
  getjwlist(){//添加学员
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.getjwlist({}).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'getjwlist',
        payload,
      });
    };
  },
  getkclist(val: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.getkclist({val}).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'getkclist',
        payload,
      });
    };
  },
  setclass(obj: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.setclass(obj).then((res)=>{
        message.success('排课成功');
        return res.data;
      })
      dispatch({
        type: 'setclass',
        payload,
      });
    };
  },
  diststudent(id: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.diststudent({id}).then((res)=>{
        message.success('删除成功');
        return res.data;
      })
      dispatch({
        type: 'diststudent',
        payload,
      });
    };
  },
  amendstudent(obj: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.amendstudent(obj).then((res)=>{
        message.success('修改成功');
        return res.data;
      })
      dispatch({
        type: 'amendstudent',
        payload,
      });
    };
  },
  setisms(id: any){
    return async (dispatch: (arg0: { type: string; payload: any; }) => void) => {
      let payload = await api.setisms({id}).then((res)=>{
        return res.data;
      })
      dispatch({
        type: 'setisms',
        payload,
      });
    };
  },
  setimage(img: any){
    return {
      type: 'setimage',
      payload:img,
    };
  },
  setimgtype(type: any){
    return {
      type: 'setimgtype',
      payload:type,
    };
  },
  
  getVersion(){
    return async (dispatch) => {
      let payload = await api.getVersion().then((res)=>{
        return res.data.data[0];
      });
      dispatch(({
        type:"getVersion",
        payload
      }))
    }
  },
  editVersionTitle(obj){
    return async (dispatch)=>{
      await api.editVersionTitle(obj).then(res=>{
        return res.data.data;
      })
      dispatch(({
        type:"editVersionTitle",
        payload:obj.title
      }))
    }
  },
  merge(obj){
    return async (dispatch) => {
      let payload = await api.merge(obj).then((res)=>{
        const { url } = res.data;
        if(url){
          return url;
        }
      });
      dispatch(({
        type:"uploadLogo",
        payload
      }))
    }
  },
  editVersionLoginRoot(obj){
    return async (dispatch) => {
      await api.editVersionLoginRoot(obj).then((res)=>{
        return res.data.data
      });
      dispatch({
        type:'editVersionLoginRoot',
        payload:obj.login_root
      })
    }
  },
  editVersionCompanyName(obj){
    return async (dispatch) => {
      await api.editVersionCompanyName(obj).then((res)=>{
        return res.data.data;
      })
      dispatch({
        type:'editVersionCompanyName',
        payload:obj.company_name
      })
    }
  },
  editVersionDuration(obj){
    return async (dispatch) => {
      await api.editVersionDuration(obj).then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'editVersionDuration',
        payload:obj.duration
      })
    }
  },
  getEmployeeList(){
    return async (dispatch) => {
      let payload = await api.getEmployeeList().then((res)=> {
        return res.data.data;
      });
      dispatch({
        type:'getEmployeeList',
        payload
      })
    }
  },
  addEmployeeList(obj){
    return async (dispatch) => {
      await api.addEmployeeList(obj).then((res)=>{
        return res.data.data;
      })
      dispatch({
        type:'addEmployeeList',
        payload:obj
      })
    }
  },
  importEmployeeDate(obj){
    return async ( dispatch ) => {
      await api.importEmployeeDate(obj).then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'importEmployeeDate',
        payload:obj.importDate
      })
    }
  },
  editEmployeeInfo(obj){
    return async (dispatch) => {
      await api.editEmployeeInfo(obj).then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'editEmployeeInfo',
        payload:obj.editObj
      })
    }
  },
  DelEmployee(obj){
    return async (dispatch) => {
      await api.DelEmployee(obj).then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'DelEmployee',
        payload:obj.delObj
      })
    }
  },
  getRoleList(){
    return async (dispatch) => {
      let payload = await api.getRoleList().then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'getRoleList',
        payload
      })
    }
  },
  addRoleList(obj){
    return async (dispatch) => {
      await api.addRoleList(obj).then((res)=>{
        return res.data.data;
      });
      dispatch({
        type:'addRoleList',
        payload:obj
      })
    }
  }
}


export default administratorActions;